import * as path from "node:path";
// import {} from "scriptjs"
import { Worker, isMainThread } from "node:worker_threads";

if (import.meta.main && isMainThread) {
  const workerPath = path.resolve(import.meta.dirname, "./worker.js");
  // 创建一个工作线程，并传入数据
  const worker = new Worker(workerPath, {
    workerData: { num: 42 }, // 传递给工作线程的数据
  });

  // 监听工作线程发来的消息
  worker.on("message", (message) => {
    console.log("Received from worker:", message);
  });

  // 监听工作线程的错误
  worker.on("error", (error) => {
    console.error("Worker error:", error);
  });

  // 监听工作线程的退出
  worker.on("exit", (code) => {
    if (code !== 0) {
      console.error(`Worker stopped with exit code ${code}`);
    }
  });
}
